// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

LL bin(LL a, LL b, LL p) {
	LL res = 1;
	for (a%=p; b; b>>=1, a=a*a%p)
		if (b & 1)
			res = res * a % p;
	return res;
}

int n;
const int N = 2e5+50;

int siz[N], sum[N];

vector<int> G[N];

int c[N];
LL ans[N];

void dfs(int u, int fa) {
	siz[u] = 1;
	int sons = 0;
	for (int v : G[u]) {
		if (v == fa)
			continue;
		int now = sum[c[u]];
		dfs(v, u);
		siz[u] += siz[v];
		int add = sum[c[u]] - now;
		ans[c[u]] += 1LL * (siz[v] - add) * (siz[v] - add + 1) / 2;
		sons += siz[v] - add;

		dbg(u, c[u], siz[v]-add, add);
	}
	sum[c[u]] += sons+1;
}

bool used[N];

int main(int argc, char const *argv[]) {
    // code
    scanf("%d", &n);
    for (int i=1; i<=n; ++i) {
    	scanf("%d", &c[i]);
    	used[c[i]] = true;
    }
    for (int i=1; i<n; ++i) {
    	int u, v;
    	scanf("%d%d", &u, &v);
    	G[u].push_back(v);
    	G[v].push_back(u);
    }

    dfs(1, 0);
    for (int i=1; i<=n; ++i) {
    	if (used[i]) {
    		ans[i] += 1LL * (n-sum[i]) * (n-sum[i]+1) / 2;
    		printf("%lld\n", 1LL*n*(n+1)/2 - ans[i]);
    	} else {
    		printf("0\n");
    	}
    }


    return 0;
}